package dao.impl;

import core.BaseDao;
import dao.DepartmentDao;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import pojo.Department;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DepartmentDaoImpl extends BaseDao implements DepartmentDao {

    /**
     * 查询所有部门
     * @return
     */
    @Override
    public List<Department> findAllDepartment() {
        try {
            sql = "SELECT * FROM department";
            return queryRunner.query(sql, new BeanListHandler<>(Department.class, rowProcessor));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return new ArrayList<>();
    }
    /**
     * 查询可修改的部门
     * @return
     */
    @Override
    public List<Department> findEditDepartment() {
        try {
            sql = "SELECT * FROM department WHERE department_code !=4";
            return queryRunner.query(sql, new BeanListHandler<>(Department.class, rowProcessor));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return new ArrayList<>();
    }
}
